//
//  HHPADCell.m
//  HHPLiveVideo
//
//  Created by 韩红坡 on 2017/4/19.
//  Copyright © 2017年 韩红坡. All rights reserved.
//

#import "HHPADCell.h"
#import "HHPADCellModel.h"
#import "SDCycleScrollView.h"

@interface HHPADCell () <SDCycleScrollViewDelegate>

/** 图片数组 */
@property (nonatomic,strong) NSMutableArray *imageUrlArray;

@property (nonatomic, strong) SDCycleScrollView *scrollView;

@property (nonatomic, strong) HHPADCellModel *adCellModel;

@end

@implementation HHPADCell
#pragma mark - life cycle
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initViews];
    }
    return self;
}

#pragma mark - GMTableViewCellProtocol
- (void)setCellModel:(HHPADCellModel *)cellModel
{
    self.adCellModel = cellModel;
    
    [self.imageUrlArray removeAllObjects];
    
    for (HHPADModel *model in cellModel.adArray) {
        [self.imageUrlArray addObject:model.imageUrl];
    }
    
    self.scrollView.imageURLStringsGroup = self.imageUrlArray;
}

#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (self.adCellModel.imageClickBlock) {
        self.adCellModel.imageClickBlock(self.adCellModel.adArray[index]);
    }
}

#pragma mark - private methods
- (void)initViews
{
    [self.contentView addSubview:self.scrollView];
    
    [self layoutPageSubviews];
}

- (void)layoutPageSubviews
{
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
}

#pragma mark - getter and setter
- (NSMutableArray *)imageUrlArray
{
    if (!_imageUrlArray) {
        _imageUrlArray = [NSMutableArray array];
    }
    
    return _imageUrlArray;
}

- (SDCycleScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeHolder_ad"]];
    }
    
    return _scrollView;
}

@end
